<%= form_for @changeset, @action, [class: "ui form", multipart: true], fn f -> %>
  <div class="three fields">
    <div class="field required <%= AdminHelpers.error_class(f, :name) %>">
      <%= label(f, :name, "Full Name") %>
      <%= text_input(f, :name, placeholder: "Grace Hopper") %>
      <%= AdminHelpers.error_message(f, :name) %>
    </div>

    <div class="field required <%= AdminHelpers.error_class(f, :email) %>">
      <label for="email">
        Email
        <%= AdminHelpers.help_icon("Personal is preferred over work-related address", "required") %>
      </label>

      <%= email_input(f, :email, placeholder: "grace@hopper.com", autocapitalize: "none") %>
      <%= AdminHelpers.error_message(f, :email) %>
    </div>

    <div class="field required <%= AdminHelpers.error_class(f, :handle) %>">
      <label for="handle">
        Handle
        <%= AdminHelpers.help_icon("Re-use social handle when applicable", "required") %>
      </label>

      <%= text_input(f, :handle, placeholder: "gracehopper", autocapitalize: "none") %>
      <%= AdminHelpers.error_message(f, :handle) %>
    </div>
  </div>

  <div class="three fields">
    <div class="field <%= AdminHelpers.error_class(f, :github_handle) %>">
      <%= label(f, :github_handle, "GitHub Handle") %>
      <%= text_input(f, :github_handle, placeholder: "gracehopper", autocapitalize: "none", mask: "slug") %>
      <%= AdminHelpers.error_message(f, :github_handle) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :twitter_handle) %>">
      <%= label(f, :twitter_handle, "Twitter Handle") %>
      <%= text_input(f, :twitter_handle, placeholder: "gracehopper", autocapitalize: "none", mask: "slug") %>
      <%= AdminHelpers.error_message(f, :twitter_handle) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :mastodon_handle) %>">
      <%= label(f, :mastodon_handle, "Mastodon Handle") %>
      <%= text_input(f, :mastodon_handle, placeholder: "gracehopper@changelog.social", autocapitalize: "none", mask: "slug") %>
      <%= AdminHelpers.error_message(f, :mastodon_handle) %>
    </div>
  </div>

  <div class="three fields">
    <div class="field <%= AdminHelpers.error_class(f, :website) %>">
      <%= label(f, :website) %>
      <%= text_input(f, :website, placeholder: "https://en.wikipedia.org/wiki/Grace_Hopper", autocapitalize: "none") %>
      <%= AdminHelpers.error_message(f, :website) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :linkedin_handle) %>">
      <%= label(f, :linkedin_handle, "LinkedIn Handle") %>
      <%= text_input(f, :linkedin_handle, placeholder: "gracehopper", autocapitalize: "none", mask: "slug") %>
      <%= AdminHelpers.error_message(f, :linkedin_handle) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :location) %>">
      <%= label(f, :location) %>
      <%= text_input(f, :location, placeholder: "New York, New York") %>
      <%= AdminHelpers.error_message(f, :location) %>
    </div>
  </div>

  <div class="two fields">
    <div class="fourteen wide field">
      <label for="avatar">
        Avatar
        <%= AdminHelpers.help_icon("Ideal size is 600px by 600px") %>
        <%= AdminHelpers.file_toggle_buttons() %>
      </label>
      <%= file_input(f, :avatar) %>
      <%= AdminHelpers.error_message(f, :avatar) %>
    </div>

    <div class="two wide field">
      <%= if AdminHelpers.is_persisted(f.data) do %>
        <img
          src="<%= ChangelogWeb.PersonView.avatar_url(f.data, :small) %>"
          data-popup=true
          <%= if !f.data.avatar do %>
            data-content="This is the fallback gravatar."
          <% else %>
            data-content="This is the uploaded file.."
          <% end %>
          width=66
          height=66
        >
      <% end %>
    </div>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :bio) %>">
    <%= label(f, :bio) %>
    <%= textarea f, :bio %>
    <%= AdminHelpers.error_message(f, :bio) %>
  </div>

<%= if Policies.Admin.Person.roles(@current_user, f.data) do %>
  <div class="ui horizontal divider">Profile</div>

  <div class="fields">
    <div class="field">
      <%= label(f, :public_profile) %>
      <div class="ui fitted toggle checkbox">
        <%= checkbox(f, :public_profile, class: "hidden") %>
      </div>
    </div>

    <div class="field">
      <%= label(f, :approved, "Can comment") %>
      <div class="ui fitted toggle checkbox">
        <%= checkbox(f, :approved, class: "hidden") %>
      </div>
    </div>
  </div>

  <div class="ui horizontal divider">Roles</div>

  <div class="fields">
    <div class="field">
      <%= label(f, :admin) %>
      <div class="ui fitted toggle checkbox">
        <%= checkbox(f, :admin, class: "hidden") %>
      </div>
    </div>

    <div class="field">
      <%= label(f, :host) %>
      <div class="ui fitted toggle checkbox">
        <%= checkbox(f, :host, class: "hidden") %>
      </div>
    </div>

    <div class="field">
      <%= label(f, :editor) %>
      <div class="ui fitted toggle checkbox">
        <%= checkbox(f, :editor, class: "hidden") %>
      </div>
    </div>
  </div>

  <div class="ui horizontal divider">Settings</div>

<%= inputs_for f, :settings, fn(i) -> %>
  <div class="ui two column stackable grid">
    <div class="column">
      <div class="inline field">
        <div class="ui toggle checkbox">
          <%= checkbox(i, :email_on_authored_news, class: "hidden") %>
          <%= label(f, :email_on_authored_news, "Email on authored news") %>
        </div>
      </div>

      <div class="inline field">
        <div class="ui toggle checkbox">
          <%= checkbox(i, :email_on_submitted_news, class: "hidden") %>
          <%= label(f, :email_on_submitted_news, "Email on submitted news") %>
        </div>
      </div>

      <div class="inline field">
        <div class="ui toggle checkbox">
          <%= checkbox(i, :email_on_comment_replies, class: "hidden") %>
          <%= label(f, :email_on_comment_replies, "Email on comment replies") %>
        </div>
      </div>
    </div>

    <div class="column">
      <div class="inline field">
        <div class="ui toggle checkbox">
          <%= checkbox(i, :email_on_comment_mentions, class: "hidden") %>
          <%= label(f, :email_on_comment_mentions, "Email on comment @mentions") %>
        </div>
      </div>

      <div class="inline field">
        <div class="ui toggle checkbox">
          <%= checkbox(i, :subscribe_to_contributed_news, class: "hidden") %>
          <%= label(f, :subscribe_to_contributed_news, "Subscribe to contributed news") %>
        </div>
      </div>

      <div class="inline field">
        <div class="ui toggle checkbox">
          <%= checkbox(i, :subscribe_to_participated_episodes, class: "hidden") %>
          <%= label(f, :subscribe_to_participated_episodes, "Subscribe to participated episodes") %>
        </div>
      </div>
    </div>
  </div>
<% end %>
<% end %>

<%= if !AdminHelpers.is_persisted(f.data) do %>
  <div class="ui horizontal divider">Welcome Email</div>

  <div class="fields">
    <div class="field">
      <label>Nope <%= AdminHelpers.help_icon("Useful for News authors because they'll get an email when their news gets published instead.") %></label>
      <div class="ui toggle radio checkbox">
        <input type="radio" name="welcome" value="" checked>
      </div>
    </div>

    <div class="field">
      <label>Generic <%= AdminHelpers.help_icon("This is the email all new community members get when they sign up. Use this if you're creating an account on someone's behalf.") %></label>
      <div class="ui toggle radio checkbox">
        <input type="radio" name="welcome" value="generic">
      </div>
    </div>

    <div class="field">
      <label>Guest <%= AdminHelpers.help_icon("This welcome email is written with guests in mind. Use this if you're creating a person to be a show guest.") %></label>
      <div class="ui toggle radio checkbox">
        <input type="radio" name="welcome" value="guest">
      </div>
    </div>
  </div>
<% end %>

  <div class="ui hidden divider"></div>
  <div class="ui equal width stackable grid">
  <%= if !AdminHelpers.is_persisted(f.data) do %>
    <div class="column"><%= AdminHelpers.submit_button(:primary, "Create") %></div>
    <div class="column"><%= AdminHelpers.submit_button(:secondary, "Create and Close", AdminHelpers.next_param(@conn, Routes.admin_person_path(@conn, :index))) %></div>
    <div class="column"></div>
  <% else %>
    <div class="column"><%= AdminHelpers.submit_button(:primary, "Save", SharedHelpers.current_path(@conn)) %></div>
    <div class="column"><%= AdminHelpers.submit_button(:secondary, "Save and Close", AdminHelpers.next_param(@conn)) %></div>
    <div class="column">
    <%= if Policies.Admin.Person.delete(@current_user, f.data) do %>
      <%= link("Delete", to: Routes.admin_person_path(@conn, :delete, f.data), class: "ui red fluid basic button", method: :delete, data: [confirm: "Are you sure?"]) %>
    <% end %>
    </div>
  <% end %>
  </div>
<% end %>
